<?php
class ImpSoft_View_Helper_DisplayDebugVar {

    /**
     * The view object that created this helper object.
     * @var Zend_View
     */
    public $view;
    
    public function displayDebugVar($var) {
    
        if (is_array($var)) return '<p><strong>Array: (' . count($var) . ' elements)</strong></p>' . $this->_displayArray($var);
        elseif (is_object($var)) return '<p><strong>Object: (' . get_class($var) . ')</strong></p>' . $this->_displayObject($var);
        else return $this->_displayDefault($var);
    
    }
    
    protected function _displayArray($array) {
    
        if (empty($array)) return '<p><strong>Empty Array</strong></p>';
        $return = '';
        foreach ($array as $key => $val) {
            $return .= "<div class='array'><strong class='key'>$key</strong>"; 
            if (is_array($val)) $return .= $this->displayDebugVar($val);
            else $return .= pr($val, true);
            $return .= '</div>';
        }
        return $return;
    
    }
    
    protected function _displayObject($obj) {
    
        $array = new ArrayObject($obj);
        if (empty($array)) return pr($obj, true);
        return $this->_displayArray($array);
    
    }
    
    protected function _displayDefault($val) {
    
        return pr($val, true);
    
    }
    /**
     * Set view object
     *
     * @param  Zend_View_Interface $view
     * @return Zend_View_Helper_DeclareVars
     */
    public function setView(Zend_View_Interface $view)
    {
        $this->view = $view;
        return $this;
    }

}
